﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Koala.Pro.Common;
using Koala.Pro.Helpers;
using System.Data;
using System.Diagnostics;
using System.IO;

namespace Koala.Pro.ViewModels
{
    public partial class ImportExcelViewModel : BaseViewModel
    {
        [ObservableProperty]
        private string templateFile;

        [ObservableProperty]
        private string importFilePath;

        [ObservableProperty]
        private DataTable items;

        public ImportExcelViewModel()
        {
            base.Title = "批量导入Excel数据";
        }

        public override void ResetViewModel()
        {
            base.ResetViewModel();
            ImportFilePath = "";
            Items?.Clear();
        }

        [RelayCommand]
        private void OpenFile()
        {
            if (!TemplateFile.IsNullOrEmpty())
            {
                string text = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TemplateFile);
                if (File.Exists(text))
                {
                    Process.Start("explorer.exe", text);
                }
                else
                {
                    MessageDxUtil.ShowError("没有找到该模板文件:" + text);
                }
            }
        }

        [RelayCommand]
        public async Task Save()
        {

        }
    }
}
